package com.momo.upms.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.momo.common.core.request.PageParams;
import com.momo.common.core.result.Rs;
import com.momo.upms.condition.UserCondition;
import com.momo.upms.dto.UserDTO;
import com.momo.upms.service.UserService;
import com.momo.upms.vo.UserVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = {"用户"})
@RestController("WebApi-User")
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = {"/page"}, method = {RequestMethod.POST})
    public Rs<Page<UserVO>> pageUser(@RequestBody PageParams<UserCondition> userCondition){
        Object principal1 = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        System.out.println(principal1);
        return userService.pageUser(userCondition);
    }

    @RequestMapping(value = {"/insert"}, method = {RequestMethod.POST})
    public Rs<UserVO> insertUser(@RequestBody UserDTO userDTO){
        return userService.insertUser(userDTO);
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    public Rs<UserVO> updateUser(@RequestBody UserDTO userDTO){
        return userService.updateUser(userDTO);
    }

    @RequestMapping(value = {"/get/{id}"}, method = {RequestMethod.GET})
    public Rs<UserVO> getUser(@PathVariable("id") Long userId){
        return userService.getUser(userId);
    }

    @RequestMapping(value = {"/delete/{id}"}, method = {RequestMethod.POST})
    public Rs<Boolean> deleteUser(@PathVariable("id") Long userId){
        return userService.deleteUser(userId);
    }

}
